package com.design.pattern.ornament.instance;

import java.io.*;

/**
 * @author wangyingjie
 * @date
 * @remark 装饰filterInputStream，实现读取内容全部小写
 */
public class MyFilterInputStream extends FilterInputStream {

    protected MyFilterInputStream(InputStream in) {
        super(in);
    }

    @Override
    public int read() throws IOException {
        int read = super.read();
        return read == -1 ? read : Character.toLowerCase(read) ;
    }

    @Override
    public int read(byte[] b) throws IOException {
        for (int i = 0; i < b.length; i++) {
            b[i] = (byte) Character.toLowerCase(b[i]);
            System.out.println((char)b[i]);
        }
        return super.read(b);
    }

    public static void main(String[] args) {
        int c ;
        byte[] bytes = new byte[5];
        try {
            MyFilterInputStream fis = new MyFilterInputStream(new BufferedInputStream(new FileInputStream("C:/Users/butterfly/Desktop/hello.txt")));
            while ((c =fis.read(bytes))>0){
                System.out.println((char)c);
            }
            fis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
